package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.PsychKnow;
import com.sfzy.service.PsychKnowService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychKnowController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月14日 10:50
 * @Version 1.0
 */
@RestController
@RequestMapping("psychKnow")
public class PsychKnowController {
    @Autowired
    private PsychKnowService psychKnowService;


    @PostMapping
    public R addPsychKnow(@RequestBody PsychKnow psychKnow){
        int i = psychKnowService.addPsychKnow(psychKnow);
        if (i==0){
            return R.fail();
        }
        return R.ok();
    }

    @PutMapping
    public R updatePsychKnow(@RequestBody PsychKnow psychKnow){
        int i = psychKnowService.updatePsychKnow(psychKnow);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deletePsychKnow(@PathVariable("id") int id){
        int i = psychKnowService.deletePsychKnow(id);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @GetMapping("{id}")
    public R selectPsychKnow(@PathVariable int id){
        PsychKnow psychKnow = psychKnowService.selectPsychKnow(id);
        return R.ok(psychKnow);
    }

    @GetMapping("pageNameContent")
    public R pageNameContent(PsychKnow psychKnow,
                             @RequestParam(required = false,defaultValue = "1") int pageNum,
                             @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<PsychKnow> psychKnowPageInfo = psychKnowService.pageNameContent(psychKnow, pageNum, pageSize);
        return R.ok(psychKnowPageInfo);

    }













}
